package com.icehand.common.enums;

import com.google.common.collect.Maps;
import com.icehand.common.exception.PayException;
import lombok.Getter;
import lombok.ToString;

import java.util.Map;

/**
 * 支付渠道枚举类
 * @author icehand
 */
@Getter
@ToString
public enum PayChannelEnum {
    /**
     * 支付宝App支付
     */
    ALI_APP_PAY(1,"支付宝","alipay_app","支付宝APP支付",PayNotifyResultEnum.ALIPAY),
    ALI_WAP_PAY(2,"支付宝","alipay_wap","支付宝WAP支付",PayNotifyResultEnum.ALIPAY),
    ALI_PC_PAY(3,"支付宝","alipay_pc","支付宝PC支付",PayNotifyResultEnum.ALIPAY),
    WECHAT_APP_PAY(4,"微信","wechat_app","微信APP支付",PayNotifyResultEnum.WECHAT),
    WECHAT_PUBLIC_ACCOUNT_PAY(5,"微信","wechat_public_account","微信公众号支付",PayNotifyResultEnum.WECHAT),
    WECHAT_H5_PAY(6,"微信","wechat_h5","微信H5支付", PayNotifyResultEnum.WECHAT),
    WECHAT_MINI_PAY(7,"微信","wechat_mini","微信小程序支付",PayNotifyResultEnum.WECHAT),
    UNION_WAP_PAY(8,"银联","unionpay_wap","银联WAP支付",PayNotifyResultEnum.UNION),
    UNION_APP_PAY(9,"银联","unionpay_app","银联APP控件支付",PayNotifyResultEnum.UNION),

    ;
    private int channelId;
    private String name;
    private String tag;
    private String desc;
    private PayNotifyResultEnum payNotifyResultEnum;

    PayChannelEnum(int channelId, String name, String tag, String desc,PayNotifyResultEnum payNotifyResultEnum){
        this.channelId = channelId;
        this.name = name;
        this.tag = tag;
        this.desc = desc;
        this.payNotifyResultEnum = payNotifyResultEnum;
    }

    public static PayChannelEnum choiceByChannelId(Integer channelId) {
        if(null != channelId){
            for(PayChannelEnum payChannelEnum : values()){
                if(payChannelEnum.getChannelId() == channelId) {
                    return payChannelEnum;
                }
            }
        }
        throw new PayException("not support pay channel，channel id :"+channelId);
    }

    public static Map<String, Object> map(PayChannelEnum payChannelEnum) {
        Map<String,Object> map = Maps.newHashMap();
        map.put("name",payChannelEnum.getName());
        map.put("channelId",payChannelEnum.getChannelId());
        map.put("desc",payChannelEnum.getDesc());
        return map;
    }
}
